package online.yysh.charging.utils;

import android.app.Activity;
import android.widget.Toast;

/**
 * 吐司工具
 */
public class ToastUtil {
    public static void showToast(final Activity act, final String msg){
        if ("main".equals(Thread.currentThread().getName())){
            Toast.makeText(act, msg, Toast.LENGTH_SHORT).show();
        }else{
            act.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(act, msg, Toast.LENGTH_SHORT).show();
                }
            });
        }
    }

    public static void showToast(final Activity act, final int stringId){
        final String msg = act.getResources().getString(stringId);
        if ("main".equals(Thread.currentThread().getName())){
            Toast.makeText(act, msg, Toast.LENGTH_SHORT).show();
        }else{
            act.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(act, msg, Toast.LENGTH_SHORT).show();
                }
            });
        }
    }
}
